'
'EWFAPITEST
'SJJ Embedded Micro Solutions
'Copyright (c) 2004 SJJ Micro Solutions    All Rights Reserved
'
'
'EWFAPITEST Form
'
' Date: 12/03/04 - Comments generated
'Test application for EWF .NET solution. The application performs the EWF functions
'on a protected drive C. You can change the drive to any drive you want.
'
'Source code is provided as is without any warranty

Imports EWFAPIC.SJJEMS.EWFAPI

Public Class frmEWFAPITEST
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

        'Get the Status for the EWF drive o nthe launch of the application.
        EWFUpdate()

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents cmdEnable As System.Windows.Forms.Button
    Friend WithEvents cmdDisable As System.Windows.Forms.Button
    Friend WithEvents txtResult As System.Windows.Forms.TextBox
    Friend WithEvents cmdCommit As System.Windows.Forms.Button
    Friend WithEvents cmdCDL As System.Windows.Forms.Button
    Friend WithEvents cmdClear As System.Windows.Forms.Button
    Friend WithEvents lblCMDResult As System.Windows.Forms.Label
    Friend WithEvents txtType As System.Windows.Forms.TextBox
    Friend WithEvents lblType As System.Windows.Forms.Label
    Friend WithEvents txtState As System.Windows.Forms.TextBox
    Friend WithEvents lblState As System.Windows.Forms.Label
    Friend WithEvents txtCMD As System.Windows.Forms.TextBox
    Friend WithEvents lblCMD As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmEWFAPITEST))
        Me.cmdEnable = New System.Windows.Forms.Button
        Me.cmdDisable = New System.Windows.Forms.Button
        Me.txtResult = New System.Windows.Forms.TextBox
        Me.cmdCommit = New System.Windows.Forms.Button
        Me.cmdCDL = New System.Windows.Forms.Button
        Me.cmdClear = New System.Windows.Forms.Button
        Me.lblCMDResult = New System.Windows.Forms.Label
        Me.txtType = New System.Windows.Forms.TextBox
        Me.lblType = New System.Windows.Forms.Label
        Me.txtState = New System.Windows.Forms.TextBox
        Me.lblState = New System.Windows.Forms.Label
        Me.txtCMD = New System.Windows.Forms.TextBox
        Me.lblCMD = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'cmdEnable
        '
        Me.cmdEnable.Location = New System.Drawing.Point(32, 40)
        Me.cmdEnable.Name = "cmdEnable"
        Me.cmdEnable.Size = New System.Drawing.Size(96, 24)
        Me.cmdEnable.TabIndex = 0
        Me.cmdEnable.Text = "Enable"
        '
        'cmdDisable
        '
        Me.cmdDisable.Location = New System.Drawing.Point(32, 80)
        Me.cmdDisable.Name = "cmdDisable"
        Me.cmdDisable.Size = New System.Drawing.Size(96, 24)
        Me.cmdDisable.TabIndex = 1
        Me.cmdDisable.Text = "Disable"
        '
        'txtResult
        '
        Me.txtResult.Location = New System.Drawing.Point(32, 208)
        Me.txtResult.Name = "txtResult"
        Me.txtResult.Size = New System.Drawing.Size(344, 20)
        Me.txtResult.TabIndex = 2
        Me.txtResult.Text = ""
        '
        'cmdCommit
        '
        Me.cmdCommit.Location = New System.Drawing.Point(152, 80)
        Me.cmdCommit.Name = "cmdCommit"
        Me.cmdCommit.Size = New System.Drawing.Size(96, 24)
        Me.cmdCommit.TabIndex = 3
        Me.cmdCommit.Text = "Commit"
        '
        'cmdCDL
        '
        Me.cmdCDL.Location = New System.Drawing.Point(32, 120)
        Me.cmdCDL.Name = "cmdCDL"
        Me.cmdCDL.Size = New System.Drawing.Size(96, 32)
        Me.cmdCDL.TabIndex = 4
        Me.cmdCDL.Text = "Commit and Disable Live"
        '
        'cmdClear
        '
        Me.cmdClear.Location = New System.Drawing.Point(152, 40)
        Me.cmdClear.Name = "cmdClear"
        Me.cmdClear.Size = New System.Drawing.Size(96, 24)
        Me.cmdClear.TabIndex = 5
        Me.cmdClear.Text = "Clear"
        '
        'lblCMDResult
        '
        Me.lblCMDResult.Location = New System.Drawing.Point(32, 184)
        Me.lblCMDResult.Name = "lblCMDResult"
        Me.lblCMDResult.Size = New System.Drawing.Size(160, 16)
        Me.lblCMDResult.TabIndex = 6
        Me.lblCMDResult.Text = "Command Result:"
        '
        'txtType
        '
        Me.txtType.Location = New System.Drawing.Point(384, 40)
        Me.txtType.Name = "txtType"
        Me.txtType.Size = New System.Drawing.Size(112, 20)
        Me.txtType.TabIndex = 7
        Me.txtType.Text = ""
        '
        'lblType
        '
        Me.lblType.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblType.Location = New System.Drawing.Point(320, 40)
        Me.lblType.Name = "lblType"
        Me.lblType.Size = New System.Drawing.Size(56, 24)
        Me.lblType.TabIndex = 8
        Me.lblType.Text = "Type:"
        '
        'txtState
        '
        Me.txtState.Location = New System.Drawing.Point(384, 72)
        Me.txtState.Name = "txtState"
        Me.txtState.Size = New System.Drawing.Size(112, 20)
        Me.txtState.TabIndex = 9
        Me.txtState.Text = ""
        '
        'lblState
        '
        Me.lblState.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblState.Location = New System.Drawing.Point(320, 72)
        Me.lblState.Name = "lblState"
        Me.lblState.Size = New System.Drawing.Size(56, 24)
        Me.lblState.TabIndex = 10
        Me.lblState.Text = "State:"
        '
        'txtCMD
        '
        Me.txtCMD.Location = New System.Drawing.Point(384, 104)
        Me.txtCMD.Name = "txtCMD"
        Me.txtCMD.Size = New System.Drawing.Size(112, 20)
        Me.txtCMD.TabIndex = 11
        Me.txtCMD.Text = ""
        '
        'lblCMD
        '
        Me.lblCMD.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblCMD.Location = New System.Drawing.Point(304, 104)
        Me.lblCMD.Name = "lblCMD"
        Me.lblCMD.Size = New System.Drawing.Size(72, 24)
        Me.lblCMD.TabIndex = 12
        Me.lblCMD.Text = "Command:"
        '
        'frmEWFAPITEST
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(520, 266)
        Me.Controls.Add(Me.lblCMD)
        Me.Controls.Add(Me.txtCMD)
        Me.Controls.Add(Me.lblState)
        Me.Controls.Add(Me.txtState)
        Me.Controls.Add(Me.lblType)
        Me.Controls.Add(Me.txtType)
        Me.Controls.Add(Me.lblCMDResult)
        Me.Controls.Add(Me.cmdClear)
        Me.Controls.Add(Me.cmdCDL)
        Me.Controls.Add(Me.cmdCommit)
        Me.Controls.Add(Me.txtResult)
        Me.Controls.Add(Me.cmdDisable)
        Me.Controls.Add(Me.cmdEnable)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "frmEWFAPITEST"
        Me.Text = "EWFAPITest"
        Me.ResumeLayout(False)

    End Sub

#End Region

#Region "Buttons Controls"



    '**************************************************************************
    'BUTTONS 
    '
    'The following are the buttons subroutine commands
    'for the application.
    '

    '--------------------------------------------------------------------------
    'cmdEnable_Click
    'Performs an EWF Enable, The Result returns a Long number that gets
    'converted into hex.
    '

    Private Sub cmdEnable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEnable.Click
        Dim EWFDrive As New EWFAPIC.SJJEMS.EWFAPI
        Dim DriveH As String = "C:"
        Dim lResult As Long
        Dim sResult As String
        Dim FResults As String


        lResult = EWFDrive.EwfEnable(DriveH)
        FResults = Hex(lResult)


        'Alternative to this select case is to change the EWFNET.DLL
        'to return a String value to put all the work in the DLL
        'instead of the .NET application.

        Select Case FResults
            Case "FFFFFFFF00000000"
                sResult = "Success - EWF Enable"
            Case "FFFFFFFF00000001"
                sResult = "Drive is Not Protected"
            Case "FFFFFFFF00000002"
                sResult = "No Such Drive (bad handle)"
            Case "FFFFFFFF00000057"
                sResult = "Requested State is Already Active"
            Case Else
                sResult = "Failure"
        End Select
        txtResult.Text = sResult
        Update()
        EWFUpdate()


    End Sub

    '--------------------------------------------------------------------------
    'cmdDisable_Click
    'Performs an EWF Disable, The Result returns a Long number that gets
    'converted into hex.
    '

    Private Sub cmdDisable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDisable.Click
        Dim EWFDrive As New EWFAPIC.SJJEMS.EWFAPI
        Dim DriveH As String = "C:"
        Dim lResult As Long
        Dim sResult As String
        Dim FResults As String

        lResult = EWFDrive.EwfDisable(DriveH, False)
        FResults = Hex(lResult)

        'Alternative to this select case is to change the EWFNET.DLL
        'to return a String value to put all the work in the DLL
        'instead of the .NET application.

        Select Case FResults
            Case "FFFFFFFF00000000"
                sResult = "Success - EWF Disabled"
            Case "FFFFFFFF00000001"
                sResult = "Drive is Not Protected"
            Case "FFFFFFFF00000002"
                sResult = "No Such Drive (bad handle)"
            Case "FFFFFFFF00000057"
                sResult = "Requested State is Already Active"
            Case Else
                sResult = "Failure"
        End Select
        txtResult.Text = sResult
        Update()
        EWFUpdate()

    End Sub
    '--------------------------------------------------------------------------
    'cmdCommit_Click
    'Performs an EWF Commit, The Result returns a Long number that gets
    'converted into hex.
    '
    Private Sub cmdCommit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCommit.Click
        Dim EWFDrive As New EWFAPIC.SJJEMS.EWFAPI
        Dim DriveH As String = "C:"
        Dim lResult As Long
        Dim sResult As String
        Dim FResults As String

        lResult = EWFDrive.EwfCommit(DriveH)
        FResults = Hex(lResult)

        'Alternative to this select case is to change the EWFNET.DLL
        'to return a String value to put all the work in the DLL
        'instead of the .NET application.

        Select Case FResults
            Case "FFFFFFFF00000000"
                sResult = "Success - Commit"
            Case "FFFFFFFF00000001"
                sResult = "Drive is Not Protected"
            Case "FFFFFFFF00000002"
                sResult = "No Such Drive (bad handle)"
            Case "FFFFFFFF00000057"
                sResult = "Requested State is Already Active"
            Case Else
                sResult = "Failure"
        End Select
        txtResult.Text = sResult
        Update()
        EWFUpdate()

    End Sub

    '--------------------------------------------------------------------------
    'cmdCDL_Click
    'Performs an EWF Commit And Disable Live, The Result returns a Long number that gets
    'converted into hex.
    '
    Private Sub cmdCDL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCDL.Click
        Dim EWFDrive As New EWFAPIC.SJJEMS.EWFAPI
        Dim DriveH As String = "C:"
        Dim lResult As Long
        Dim sResult As String
        Dim FResults As String

        lResult = EWFDrive.EwfCommitandDisableLive(DriveH)
        FResults = Hex(lResult)

        'Alternative to this select case is to change the EWFNET.DLL
        'to return a String value to put all the work in the DLL
        'instead of the .NET application.

        Select Case FResults
            Case "FFFFFFFF00000000"
                sResult = "Success - EWF Disabled / Commit"
            Case "FFFFFFFF00000001"
                sResult = "Drive is Not Protected"
            Case "FFFFFFFF00000002"
                sResult = "No Such Drive (bad handle)"
            Case "FFFFFFFF00000057"
                sResult = "Requested State is Already Active"
            Case Else
                sResult = "Failure"
        End Select
        txtResult.Text = sResult
        Update()
        EWFUpdate()

    End Sub

    '--------------------------------------------------------------------------
    'cmdClear_Click
    'Performs an EWF Clear, The Result returns a Long number that gets
    'converted into hex.
    '


    Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClear.Click
        Dim EWFDrive As New EWFAPIC.SJJEMS.EWFAPI
        Dim DriveH As String = "C:"
        Dim lResult As Long
        Dim sResult As String
        Dim FResults As String

        lResult = EWFDrive.EwfClearCommand(DriveH)
        FResults = Hex(lResult)

        'Alternative to this select case is to change the EWFNET.DLL
        'to return a String value to put all the work in the DLL
        'instead of the .NET application.

        Select Case FResults
            Case "FFFFFFFF00000000"
                sResult = "Success - Clear"
            Case "FFFFFFFF00000001"
                sResult = "Drive is Not Protected"
            Case "FFFFFFFF00000002"
                sResult = "No Such Drive (bad handle)"
            Case Else
                sResult = "Failure"
        End Select
        txtResult.Text = sResult
        Update()
        EWFUpdate()

    End Sub

#End Region

    '--------------------------------------------------------------------------
    'cmdEWFUpdate
    'This subroutine makes three seperate calls to get the status of the EWF
    'drive - Type, State, Current Boot Command.
    'The routine is called by each of the button routines above as well as
    'the start of the application.

    Sub EWFUpdate()
        Dim EWFDrive As New EWFAPIC.SJJEMS.EWFAPI
        Dim DriveH As String = "C:"
        Dim sType As String
        Dim sState As String
        Dim sCommand As String

        sType = EWFDrive.EWFStatus_Type(DriveH)
        sState = EWFDrive.EWFStatus_State(DriveH)
        sCommand = EWFDrive.EWFStatus_Command(DriveH)

        txtType.Text = sType
        txtState.Text = sState
        txtCMD.Text = sCommand
        Update()

    End Sub


End Class
